package com.pacific.sign.biz.wrapper;
import com.pacific.common.exception.BizException;
import com.pacific.common.response.CommonResponse;
import com.pacific.common.response.Error;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 公用包装返回码
 */
public class CommonWrapper {
	private final Logger log = LoggerFactory.getLogger(CommonWrapper.class);

	/**
	 * 系统号  101
	 */
	private final String SystemId = "101";
	private final String SystemMsg = "hc : ";


	public void wrapper(CommonResponse response, Exception e){
		if(e instanceof BizException){
			log.error(e.getMessage(),e);
			response.setError(new Error());
			response.getError().setCode(SystemId + ((BizException) e).getErrcode());
			response.getError().setMessage(e.getMessage());
			response.setResult(null);
		}else if(e instanceof Exception){
			log.error("系统异常",e);
			response.setError(new Error());
			response.getError().setCode(SystemId + "-100");
			response.getError().setMessage(SystemMsg + "系统异常");
			response.setResult(null);
		}else if( e==null){
			response.setSuccess(true);
			response.setError(null);
		}
	}
	
	public void wrapper(CommonResponse response){
		wrapper(response,null);
	}
}
